package com.baixun.gassystem.service.impl;

import com.alibaba.fastjson.JSONArray;
import com.baixun.gascommon.config.ApiConfig;
import com.baixun.gasentity.dto.DeviceStatisticsDto;
import com.baixun.gasentity.dto.MonitorStatisticsDTO;
import com.baixun.gasentity.entity.Point;
import com.baixun.gassystem.mapper.PointMapper;
import com.baixun.gassystem.mapper.SysMonitorStatisticsMapper;
import com.baixun.gassystem.service.ApiService;
import com.baixun.gassystem.service.HomePageService;
import com.baixun.gassystem.service.SysMonitorStatisticsService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.net.HttpURLConnection;
import java.net.URL;
import java.util.List;
import java.util.Map;

/**
 * @program: 上海燃气驾驶舱
 * @description: 通过查询sys_Monitor_statistics返回MonitorStatisticsDTO实现类
 * @create: 2020-08-06 15:06
 * @author: yesong
 **/

@Service
public class SysMonitorStatisticsServiceImpl implements SysMonitorStatisticsService {

    @Autowired
    private SysMonitorStatisticsMapper sysMonitorStatisticsMapper;

    @Autowired
    private HomePageService homePageService;

    @Autowired
    private PointMapper pointMapper;

    /**
     * 查询并返回监控统计数据
     *
     * @return 监控统计数据传输对象
     */
    @Override
    public MonitorStatisticsDTO selectCount() throws Exception {

        int aicounts= homePageService.getsuanfa();
        // 查询所有 pointId
        QueryWrapper<Point> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("pointId");
        List<Object> counts= pointMapper.selectObjs(queryWrapper);
        int totalCounts = counts.size();
        int noAiCount = totalCounts - aicounts;
        MonitorStatisticsDTO monitorStatisticsDTO = new MonitorStatisticsDTO();
        monitorStatisticsDTO.setTotalCount(totalCounts);
        monitorStatisticsDTO.setAiTrue(aicounts);
        monitorStatisticsDTO.setAiFalse(noAiCount);
        return monitorStatisticsDTO;
    }

    /**
     * 查询并返回设备统计数据
     *
     * @return 设备统计数据传输对象
     */
    @Override
    public List<DeviceStatisticsDto> selectDeviceCount( String deviceType) {
        return sysMonitorStatisticsMapper.selectDeviceCount(deviceType);
    }
}
